package com.ruoyi.tactics.service.impl;

import com.ruoyi.tactics.ZodiacApply;
import com.ruoyi.tactics.ZodiacResult;
import com.ruoyi.tactics.algorithm.EZEAlgorithm;
import com.ruoyi.tactics.algorithm.*;
import com.ruoyi.tactics.enums.PlayEnum;
import com.ruoyi.tactics.service.AlgorithmService;
import org.springframework.stereotype.Service;

@Service
public class AlgorithmServiceImpl implements AlgorithmService {

    @Override
    public boolean playAlgorithm(ZodiacResult result, ZodiacApply zodiacApply) {
        String[] codes = zodiacApply.getCodes().split(",");
        return algorithm(PlayEnum.getEnum(zodiacApply.getType())).isWin(result, codes);
    }

    private AbstractAlgorithm algorithm(PlayEnum type) {
        AbstractAlgorithm algorithm = null;
        switch (type) {
            case TM:
                algorithm = new TMAlgorithm();
                break;
            case TC:
                algorithm = new TCAlgorithm();
                break;
            case MZ:
                algorithm = new MZAlgorithm();
                break;
            case EZE:
                algorithm = new EZEAlgorithm();
                break;
            case SZE:
                algorithm = new SZEAlgorithm();
                break;
            case SZS:
                algorithm = new SZSAlgorithm();
                break;
            case ONE_ZODIAC:
                algorithm = new OneZodiacAlgorithm();
                break;
            case TWO_ZODIAC:
                algorithm = new TwoZodiacAlgorithm();
                break;
            case THREE_ZODIAC:
                algorithm = new ThreeZodiacAlgorithm();
                break;
            case FOUR_ZODIAC:
                algorithm = new FourZodiacAlgorithm();
                break;
            case FIVE_ZODIAC:
                algorithm = new FiveZodiacAlgorithm();
                break;
            case HONB:
                algorithm = new HONBAlgorithm();
                break;
            case LVB:
                algorithm = new LVBAlgorithm();
                break;
            case LANB:
                algorithm = new LANBAlgorithm();
                break;
            case WBZ:
                algorithm = new WBZAlgorithm();
                break;
            case WZY:
                algorithm = new WZYAlgorithm();
                break;
        }
        return algorithm;
    }
}
